<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue@2_dist_vue.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>

<div id="app">
    {{ message }}
    <p v-if="seen">现在你看到我了</p>
    <ol>
        <li v-for="todo in todos">
            {{ todo.text }}-{{todo.id}}
        </li>
    </ol>
    <input v-model="message">
    <button v-on:click="reverseMessage">反转消息</button>
    <button v-on:click="toggle">{{title}}</button>
    <button @click="getAllRoles">加载所有角色</button>
    <ol>
        <li v-for="role in roleList">
            {{ role.id }}-{{role.roleName}}
        </li>
    </ol>
</div>

<script>
    var app = new Vue({
        el: '#app',
        data: {
            title: '隐藏',
            message: '页面加载于 ' + new Date().toLocaleString(),
            seen: true,
            todos: [
                { text: '学习 JavaScript',id: 1 },
                { text: '学习 Vue',id: 2 },
                { text: '整个牛项目',id: 3 }
                ],
            roleList: [],
        },
        methods: {
            reverseMessage() {
                this.message = this.message.split('').reverse().join('')
            },
            toggle() {
                if (this.title == '显示') {
                    this.title = '隐藏'
                    this.seen = true
                } else {
                    this.title = '显示'
                    this.seen = false
                }
            },
            getAllRoles() {
                axios.get('http://localhost:8080/ssm_01_war_exploded/roles/getAll')
                    .then((response) => {
                        this.roleList = response.data
                    })
                    .catch(function (error) {
                        // 处理错误情况
                        console.log(error);
                    })
            }
        }
    })
</script>
</body>
</html>